4 * @group ResourceLoader
6 class ResourceLoaderImageTest
extends ResourceLoaderTestCase
{
10 protected function setUp() {
12 $this->imagesPath
= __DIR__
. '/../../data/resourceloader';
15 protected function getTestImage( $name ) {
16 $options = ResourceLoaderImageModuleTest
::$commonImageData[$name];
17 $fileDescriptor = is_string( $options ) ?
$options : $options['file'];
18 $allowedVariants = is_array( $options ) && isset( $options['variants'] ) ?
$options['variants'] : array();
19 $variants = array_fill_keys( $allowedVariants, array( 'color' => 'red' ) );
20 return new ResourceLoaderImageTestable( $name, 'test', $fileDescriptor, $this->imagesPath
, $variants );
23 public static function provideGetPath() {
25 array( 'add', 'en', 'add.gif' ),
26 array( 'add', 'he', 'add.gif' ),
27 array( 'remove', 'en', 'remove.svg' ),
28 array( 'remove', 'he', 'remove.svg' ),
29 array( 'next', 'en', 'next.svg' ),
30 array( 'next', 'he', 'prev.svg' ),
31 array( 'help', 'en', 'help-ltr.svg' ),
32 array( 'help', 'ar', 'help-rtl.svg' ),
33 array( 'help', 'he', 'help-ltr.svg' ),
34 array( 'bold', 'en', 'bold-b.svg' ),
35 array( 'bold', 'de', 'bold-f.svg' ),
36 array( 'bold', 'ar', 'bold-f.svg' ),
37 array( 'bold', 'fr', 'bold-a.svg' ),
38 array( 'bold', 'he', 'bold-a.svg' ),
43 * @covers ResourceLoaderImage::getPath
44 * @dataProvider provideGetPath
46 public function testGetPath( $imageName, $languageCode, $path ) {
47 static $dirMap = array(
54 static $contexts = array();
56 $image = $this->getTestImage( $imageName );
57 $context = $this->getResourceLoaderContext( $languageCode, $dirMap[$languageCode] );
59 $this->assertEquals( $image->getPath( $context ), $this->imagesPath
. '/' . $path );
63 * @covers ResourceLoaderImage::getExtension
64 * @covers ResourceLoaderImage::getMimeType
66 public function testGetExtension() {
67 $image = $this->getTestImage( 'remove' );
68 $this->assertEquals( $image->getExtension(), 'svg' );
69 $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
70 $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
71 $image = $this->getTestImage( 'add' );
72 $this->assertEquals( $image->getExtension(), 'gif' );
73 $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
74 $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
78 * @covers ResourceLoaderImage::getImageData
79 * @covers ResourceLoaderImage::variantize
80 * @covers ResourceLoaderImage::massageSvgPathdata
82 public function testGetImageData() {
83 $context = $this->getResourceLoaderContext( 'en', 'ltr' );
85 $image = $this->getTestImage( 'remove' );
86 $data = file_get_contents( $this->imagesPath
. '/remove.svg' );
87 $dataConstructive = file_get_contents( $this->imagesPath
. '/remove_variantize.svg' );
88 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
89 $this->assertEquals( $image->getImageData( $context, 'destructive', 'original' ), $dataConstructive );
90 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
91 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
93 $image = $this->getTestImage( 'add' );
94 $data = file_get_contents( $this->imagesPath
. '/add.gif' );
95 $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
96 $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
100 * @covers ResourceLoaderImage::massageSvgPathdata
102 public function testMassageSvgPathdata() {
103 $image = $this->getTestImage( 'next' );
104 $data = file_get_contents( $this->imagesPath
. '/next.svg' );
105 $dataMassaged = file_get_contents( $this->imagesPath
. '/next_massage.svg' );
106 $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
110 class ResourceLoaderImageTestable
extends ResourceLoaderImage
{
111 // Make some protected methods public
112 public function getPath( ResourceLoaderContext
$context ) {
113 return parent
::getPath( $context );
115 public function massageSvgPathdata( $svg ) {
116 return parent
::massageSvgPathdata( $svg );
118 // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
119 public function rasterize( $svg ) {
120 return 'RASTERIZESTUB';